package com.seguriapp.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.seguriapp.dao.PaperworkDao;
import com.seguriapp.entities.Paperwork;
import com.seguriapp.entities.PaperworkAttribute;

/**
 * Paperwork Service Implementation
 * 
 * @author Tania Gonzales (taniadgv@gmail.com)
 */
@Service
public class PaperworkServiceImpl implements PaperworkService {

  @Autowired
  private PaperworkDao paperworkDao;

  public void setPaperworkDao(final PaperworkDao paperworkDao) {
    this.paperworkDao = paperworkDao;
  }

  @Transactional
  public List<Paperwork> listActivePaperwork() {
    final List<Paperwork> responseList = paperworkDao.listActivePaperwork();
    for (final Paperwork paperwork : responseList) {
      final List<PaperworkAttribute> attributeList = paperworkDao.getPaperworkAttributeList(paperwork.getId());
      paperwork.setAttributeList(attributeList);
    }
    return responseList;
  }

  @Transactional
  public Paperwork findPaperworkById(Long paperworkId) {
    return paperworkDao.findById(paperworkId);
  }

}
